package com.deer.wms.base.system.service.box.impl;

import com.deer.wms.base.system.dao.box.AreaBoxItemHistoryMapper;
import com.deer.wms.base.system.dao.box.AreaBoxItemMapper;
import com.deer.wms.base.system.model.box.AreaBoxItem;
import com.deer.wms.base.system.model.box.AreaBoxItemDto;
import com.deer.wms.base.system.model.box.AreaBoxItemHistory;
import com.deer.wms.base.system.model.box.BoxTurnover;
import com.deer.wms.base.system.service.box.AreaBoxItemHistoryService;
import com.deer.wms.base.system.service.box.AreaBoxItemService;
import com.deer.wms.common.core.service.AbstractService;
import com.deer.wms.common.core.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaBoxItemHistoryServiceImpl extends AbstractService<AreaBoxItemHistory, Integer> implements AreaBoxItemHistoryService {
    @Autowired
    private AreaBoxItemHistoryMapper areaBoxItemHistoryMapper;
    @Override
    public AreaBoxItemHistory findAreaBoxItemById(Integer id) {
        return areaBoxItemHistoryMapper.findAreaBoxItemById(id);
    }

    @Override
    public List<AreaBoxItemDto> findAreaBoxItemList(AreaBoxItemDto areaBoxItemDto) {
        return areaBoxItemHistoryMapper.findAreaBoxItemList(areaBoxItemDto);
    }

    @Override
    public int delectAreaBoxItembyId(Integer id) {
        return areaBoxItemHistoryMapper.delectAreaBoxItembyId(id);

    }

    @Override
    public int delectAreaBoxItemByIds(String ids) {
        return areaBoxItemHistoryMapper.delectAreaBoxItemByIds(Convert.toStrArray(ids));

    }

    @Override
    public int editAreaBoxItem(AreaBoxItem areaBoxItem) {
        return areaBoxItemHistoryMapper.editAreaBoxItem(areaBoxItem);

    }

    @Override
    public int saveAreaBoxItem(AreaBoxItem areaBoxItem) {
        return areaBoxItemHistoryMapper.saveAreaBoxItem(areaBoxItem);

    }

    @Override
    public List<AreaBoxItemDto> findListItem() {
        return areaBoxItemHistoryMapper.findListItem();
    }

    @Override
    public void saveTurnoverMSG(BoxTurnover boxTurnover) {
        areaBoxItemHistoryMapper.saveTurnoverMSG(boxTurnover);
    }

    @Override
    public List<BoxTurnover> findBoxTurnoverList() {
        return areaBoxItemHistoryMapper.findBoxTurnoverList();
    }

    @Override
    public List<BoxTurnover> selectBoxTurnoverList(BoxTurnover boxTurnover) {
        List<BoxTurnover> boxTurnoverList = areaBoxItemHistoryMapper.selectBoxTurnoverList(boxTurnover);
        int overDay = boxTurnover.getOverDay();//天数
        for (BoxTurnover el : boxTurnoverList) {
            if(el.getOutWeight()==null){
                el.setOutWeight(1.0);
            }
            if(el.getStaWeight()==null){
                el.setStaWeight(0.0);
            }
            if(el.getEndWeight()==null){
                el.setEndWeight(0.0);
            }
            Double turnover = 360/(overDay * 0.5 * (el.getStaWeight()+el.getEndWeight())/el.getOutWeight());
            el.setTurnover(turnover);
        }

        return boxTurnoverList ;
    }
}
